<!DOCTYPE html>
<html>
<head>@include('/common/header.html',{"title":"控制台"}){}
<link rel="stylesheet" href="${baseStaticUrl}/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${baseStaticUrl}/plugins/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${baseStaticUrl}/plugins/ztree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript">
//角色树
var zTreeObj;
var roleType = "";
var roleId = 0;
var deptRole = "";
var roleName = "";
//节点单击事件
function onRoleClick(event,treeId,treeNode){
    roleId = treeNode.id;
    roleName = treeNode.name;
    var parentRole = treeNode.getParentNode();
    var parentId = roleId;
    if(parentRole != null){
        parentId = parentRole.id;
    }
    roleType = "";
    deptRole = "";
    if(parentId == -1){
        roleType = "sys";
    }
    initDelBtn();
    $("#sysUserRoleTable").bootstrapTable("refresh");
}
function queryParamFunc() {
    return {
        roleType:roleType,
        roleId:roleId,
        deptRole:deptRole
    };
}
function allocateUser() {
    if(roleId <= 0){
        MessageBox.error("请选择角色！")
    }else{
        _tabs.showPage("allocateUser",null,'roleType=' + roleType + '&roleId=' + roleId + '&deptRole=' + deptRole + '&roleName=' + encodeURIComponent(roleName),null);
    }
}
function initDelBtn(){
}
function delRow(id) {
}
function adjustHeight(){
    $(".adjHeight").height(null);
    $(".adjHeight").css("min-height",($(window).height() - 180) + "px");
    $(".adjHeight").outerHeight($(document).height() - 180);
}
</script>
</head>
<body>
<body class="hold-transition skin-blue sidebar-mini">
<div class='toolbar row'>
	<div class='col-xs-12 _common_head_bar_css'>
		<span class="headTitle">用户角色分配</span>
		<div style="margin-top: 10px;margin-right: 10px;">
		<button id='${headToolbarId!"_common_head_bar"}_Save' style="display: none"
                class="btn btn-primary btn-sm" >
            <span class="glyphicon glyphicon-save" aria-hidden="true"></span>保存
    	</button>
		</div>
	</div>
</div>
<section class="content">
	<div class="box box-primary">
		<div class="box-body">
			<div class="row">
				<div class="col-sm-2">
					<ul id="roleTree" class="ztree"></ul>
				</div>
				<div class="col-sm-10">
					<div class="table-responsive">
				        <epoch:table id="sysUserRoleTable" queryUrl="${basePath}/sys/userrole/findRoleUsersAjax" rowId="id"
				            queryParam="queryParamFunc" showRefresh="true"  delBtn="false">
				            <epoch:moreBtn position="0">
			                    <button type="button" class="btn btn-primary btn-sm" onclick="allocateSysRole()">
			                        <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>分配用户
			                    </button>
			                    <button type="button" class="btn btn-primary btn-sm" onclick="allocateAllSysRole()">
			                        <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>分配所有用户
			                    </button>
			                    <button type="button" class="btn btn-primary btn-sm" onclick="deleteSysRole()">
			                        <span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>移除用户
			                    </button>
			                    <button type="button" class="btn btn-primary btn-sm" onclick="removeAllSysRole()">
			                        <span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>移除所有用户
			                    </button>
			                </epoch:moreBtn>
				            <epoch:tr check="checkbox" titleTip="全选" width="5%"></epoch:tr>
				            <epoch:tr name="员工编号" formName="employee_number" cssClass="noWrap" width="10%"></epoch:tr>
				            <epoch:tr name="姓名" formName="user_name" cssClass="noWrap" width="10%"></epoch:tr>
				            <epoch:tr name="状态" formName="status" cssClass="stsMinWidth noWrap" width="5%" filterType="select"
				                filterData="${lisFun.dictForFilter('SYS_USER_STATUS')}"></epoch:tr>
				            <epoch:tr name="部门" formName="dept_name" width="10%"></epoch:tr>
				            <epoch:tr name="${lisFun.escapeForQuot(lisFun.getDictCode('SYS_ROLE_TYPE','SYSTEM'))}" formName="sys_role_names" cssClass="longText" width="25%"></epoch:tr>
				        </epoch:table>
			        </div>
				</div>
			</div>
		</div>
	</div>
</section>
<!--用户角色分配弹窗-->
<epoch:winOpen id="allocateSysRole" title="角色选择弹框" backdrop="true"
            width="1180px">
     <div class="row visa-row">
       <div class="row w-row">
           <div class="col-md-1 col-xs-12 w-row1">角色名称</div>
                <div class="col-md-3 col-xs-12 w-row2">
                       <input type="text" class="form-control form-control-sm" readonly="readonly"
                       value="" id="roleNameId"></div>
                 <div class="col-md-1 col-xs-12 w-row1"></div>
                 <div class="col-md-3 col-xs-12 w-row2"></div>
                 <div class="col-md-1 col-xs-12 w-row1"></div>
                 <div class="col-md-3 col-xs-12 w-row2"></div>
        </div>
    </div>    
    <epoch:table id="sysUserTable" queryUrl="${basePath}/sys/user/findUserListAjax" rowId="id" showRefresh="true">
          <epoch:tr check="checkbox" titleTip="全选"></epoch:tr>
          <epoch:tr name="员工编号" formName="employee_number"></epoch:tr>
          <epoch:tr name="用户名" formName="full_name"></epoch:tr>
          <epoch:tr name="邮箱" formName="email"></epoch:tr>
          <epoch:tr name="联系方式" formName="phone_number"></epoch:tr>
          <epoch:tr name="所属公司" formName="company_name"></epoch:tr>
          <epoch:tr name="部门" formName="dept_name"></epoch:tr>
          <epoch:tr name="员工状态" formName="status"
              filterType="select" filterData="${lisFun.dictForFilter('SYS_USER_STATUS')}"></epoch:tr>
     </epoch:table>
</epoch:winOpen>
</body>
<script type="text/javascript">
$(window).resize(function(){
    adjustHeight();
});
$(document).ready(function () {
    $("#sysUserRoleTable").on("post-body.bs.table",function(e){
        adjustHeight();
        $("#sysUserRoleTable td.longText").each(function(i,td){
            var $td = $(td);
            $td.attr("title",$td.text());
        });
    });
    adjustHeight();
    var setting = {
        check:{enable:false},
        data:{
            simpleData:{enable:true}
        },
        callback:{
            onClick:onRoleClick
        }
    };
    var zNodes = [{
        name: "系统角色",
        id: "-1",
        open:true,
        children:${sysRoles}
    }];
    zTreeObj = $.fn.zTree.init($("#roleTree"),setting,zNodes);
});

function allocateSysRole (){
	if(roleId <= 0){
        MessageBox.error("请先选择具体角色！")
    }else{
    	$("#roleNameId").val(roleName);
    	$("#allocateSysRole").modal('show');
    }
}

function deleteSysRole(rows){
	CommonUtil.del(rows, "id", "${basePath}/sys/userrole/deleteSysRole", null, function (data) {
		MessageBox.success("删除成功！");
		$("#sysUserRoleTable").bootstrapTable("refresh");
   });
}


$("#allocateSysRole_save").click(function() {
	var obj = {};
    obj.roleType = roleType;
    obj.roleId = roleId;
    obj.deptRole = "";
    var selected = $("#sysUserTable").bootstrapTable("getAllSelections");
    if (isEmpty(selected)) {
        MessageBox.error("请至少选择一行记录！");
        return;
    }
    var ids = [];
    for (var id in selected) {
        ids.push(selected[id].id);
    }
    obj.ids = ids;
    //异步提交表单
    $.post("${basePath}/sys/userrole/save", obj, function (result) {
        if (result.code != 0) {
            MessageBox.error("保存失败！")
            return;
        } else {
            MessageBox.success("保存成功。");
            $("#allocateSysRole").modal('hide');
            $("#sysUserRoleTable").bootstrapTable("refresh");
        }
    });
});
</script>
</html>